/*
 * binary_search.c
 *
 *  Created on: Mar 25, 2014
 *      Author: jack
 */
#include<stdio.h>

void binary_search(int arr[], int len,int key) {
	int start=0,end=len-1,mid;
	while(start<=end) {
		mid = (start+end)/2;
		if(key < arr[mid]) {
			end = mid-1;
		}else if(key > arr[mid]) {
			start = mid+1;
		}else {
			printf("find %d\n",key);
			break;
		}
	}
	if(start>end) {
		printf("search failed!\n");
	}
}
